package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.domain.ShopingCar;
import cn.wolfcode.trip.base.query.ProductQueryObject;
import cn.wolfcode.trip.base.service.IProductService;
import cn.wolfcode.trip.base.service.IShopingCarService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Pageable;
import java.util.List;

/**
 * 结伴游接口
 */
@RestController
@RequestMapping("products")
public class ProductController {
    @Autowired
    private IProductService productService;

    @Autowired
    private IShopingCarService shopingCarService;

    /**
     * 产品列表的高级查询
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo list(ProductQueryObject qo){
        PageInfo pageInfo = productService.query(qo);
        return pageInfo;
    }

    /**
     * 查询某一产品信息
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Product getProduct(@PathVariable("id") Long id){
        Product product = productService.selectProductById(id);
        return product;
    }

    /**
     * 保存或者更新购物车
     * @param car
     * @return
     */
    @PostMapping("{product.id}")
    public JSONResult saveOrUpdate(ShopingCar car){
        shopingCarService.saveOrUpdate(car);
        return new JSONResult();
    }

    /**
     * 查询订单商品
     * @param ids
     * @return
     */
    @GetMapping("order")
    public List<Product> getOrderProducts(Long[] ids){
        List<Product> list = productService.getOrderProducts(ids);
        return list;
    }
}
